package com.example.barcodeapp.ui.home.activity;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.barcodeapp.MainActivity;
import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.FragmentAdapter;
import com.example.barcodeapp.base.BaseActivity;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.interfaces.IBasePersenter;
import com.example.barcodeapp.interfaces.own.IOwn;
import com.example.barcodeapp.persenter.own.OnePresenter;
import com.example.barcodeapp.persenter.own.OnePresenterjiaoshijiemian;
import com.example.barcodeapp.ui.home.bean.JiaoShiNeiRongBean;
import com.example.barcodeapp.ui.home.fragment.GatherFragment;
import com.example.barcodeapp.ui.home.fragment.JiaoshiFragment;
import com.example.barcodeapp.ui.own.bean.LanMuBean;
import com.example.barcodeapp.ui.own.fragment.OwnFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;

public class JiangshiActivity extends BaseActivity<IOwn.Persenterjiaoshi> implements IOwn.Viewjiaoshi {
    ViewPager viewPager;
    private TabLayout tabLayout;
    private ArrayList<Fragment> fragments;
    private FragmentAdapter fragmentAdapter;

    @Override
    protected int getLayout() {
        return R.layout.jiangshi_activity;
    }

    @Override
    protected void initView() {
        setToolBar(true, false, true, false, false);
        setTitle("季风名师", R.color.black, R.color.white);
        viewPager = (ViewPager) findViewById(R.id.viewPager);
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        fragments = new ArrayList<>();


    }

    @Override
    protected OnePresenterjiaoshijiemian initPersenter() {
        return new OnePresenterjiaoshijiemian();
    }

    @Override
    protected void initData() {
        persenter.getjiaoshineironglanmu();
//        persenter.getjiaoshineirong(Constants.lanmuid,2);
    }

    @Override
    public void getjiaoshineirong(JiaoShiNeiRongBean xiLieKeBean) {



    }

    @Override
    public void getjiaoshineironglanmu(LanMuBean xiLieKeBean) {
        for (int i = 0; i < xiLieKeBean.getData().size(); i++) {
            fragments.add(new JiaoshiFragment());
        }
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(fragmentAdapter);
        tabLayout.setupWithViewPager(viewPager);

        tabLayout.setTabIconTint(null);//显示图片
        for (int i = 0; i < xiLieKeBean.getData().size() ; i++) {
            tabLayout.getTabAt(i).setText(xiLieKeBean.getData().get(i).getLanmu());
        }
        tabLayout.setSelectedTabIndicatorHeight(0);
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Constants.jiasohilanmuid=xiLieKeBean.getData().get(tab.getPosition()).getId();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }


//    @Override
//    protected OnePresenterjiaoshijiemian initPersenter() {
//        return new OnePresenterjiaoshijiemian();
//    }
//
//
//    @Override
//    protected void initData() {
//        persenter.getjiaoshineirong(Constants.lanmuid,2);
//    }


}
